package luongvd.weather.model.entity;

import java.io.IOException;
import java.util.ArrayList;

import luongvd.weather.model.dbhelper.DatabaseHandler;
import luongvd.weather.model.object.ObjectCity;
import luongvd.weather.model.object.ObjectForecast;
import luongvd.weather.model.object.ObjectWeather;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class EntityWeather {

	private final Context mContext;
	private SQLiteDatabase mDb;
	private DatabaseHandler mDbHelper;
	
	public EntityWeather(Context context) 
	{
	    this.mContext = context;
	    mDbHelper = new DatabaseHandler(mContext);
	}
	
	public ObjectCity getInfoWeatherView()
	{
		return mDbHelper.getInfoWeatherView();
	}
	
	public ArrayList<ObjectWeather> getInfoWeatherAllLocation()
	{
		return mDbHelper.getInfoWeatherAllLocation();
	}
	
	public ArrayList<ObjectWeather> getInfoWeather(String name)
	{
		return mDbHelper.getInfoWeather(name);
	}
	
	public ArrayList<ObjectForecast> getInfoForecast(String name)
	{
		return mDbHelper.getInfoForecast(name);
	}
	
	public EntityWeather createDatabase() throws SQLException 
	{
	    try 
	    {
	        mDbHelper.createDataBase();
	    } 
	    catch (IOException mIOException) 
	    {
	    }
	    return this;
	}
	
	public EntityWeather open() throws SQLException 
	{
	    try 
	    {
	        mDbHelper.openDataBase();
	        mDbHelper.close();
	        mDb = mDbHelper.getWritableDatabase();
	    } 
	    catch (SQLException mSQLException) 
	    {
	        throw mSQLException;
	    }
	    return this;
	}

	public void close() 
	{
	    mDbHelper.close();
	}
	
}
